<template>
  <div class="" v-title data-title="内控平台-风控矩阵-问题整改">
    <a-back-top></a-back-top>
    <index-header headLine="问题整改" hideBack></index-header>
    <div class="content info-main">
      <header>
        <h1>问题整改</h1>
      </header>
      <h2><a-icon type="file-done" />风险点信息</h2>
      <a-descriptions bordered size="small" class="internal">
        <a-descriptions-item label="法人公司">
          {{form.companyName}}
        </a-descriptions-item>
        <a-descriptions-item label="考核经营体">
          {{form.manageName}}
        </a-descriptions-item>
        <a-descriptions-item label="业务模块">
          {{form.businessModelName}}
        </a-descriptions-item>
        <a-descriptions-item label="L1">
          {{form.incRisk.level1Name}}
        </a-descriptions-item>
        <a-descriptions-item label="L2">
           {{form.incRisk.level2Name}}
        </a-descriptions-item>
        <a-descriptions-item label="风险点编号">
          {{form.incRisk.riskNo}}
        </a-descriptions-item>
        <a-descriptions-item label="风险因素">
        {{form.incRisk.riskFactor}}
        </a-descriptions-item>
        <a-descriptions-item label="风险事件">
          {{form.incRisk.riskEvent}}
        </a-descriptions-item>
        <a-descriptions-item label="风险类型">
          {{form.incRisk.riskTypeName}}
        </a-descriptions-item>
      </a-descriptions>
      <a-divider />
      <div>
        <a-button type="primary" icon="plus" @click="handleCreate(1)"
                  v-has-permi="['que:edit']"
        >创建问题单</a-button>
        <a-button type="primary" icon="plus" @click="handleCreate(2)" v-has-permi="['opt:edit']">创建优化单</a-button>

      </div>

      <template>
        <div class="mt20">
          <div class="tabs">
            <div v-for="item in tabsList" :key="item.key" :class="{ active: item.key == tabsId }" @click="handChange(item)">
              <span>{{ item.name }}</span>
            </div>
          </div>
          <section class="section-bg">
            <a-table
              class="risk-mini-size-table"
              :loading="pagination.loading"
              :columns="tabsId==1?dataColumns:dataColumns2"
              :data-source="dataList"
              :pagination="pagination"
              bordered
              @change="pageChange"
              rowKey="id"
              :scroll="{ x: true }"
            >
              <template slot="textOver" slot-scope="text">
                <span class="text-over" :title="text">{{ text }}</span>
              </template>
              <template slot="isFlag" slot-scope="text">
                <span :title="text">{{ text?'是':'否' }}</span>
              </template>

              <template v-if="tabsId == 1" slot="status" slot-scope="text ,record">
                <span v-if="record.status == 1">草稿</span>
                <span v-if="record.status == 2">处理中</span>
                <span v-if="record.status == 3">已完成</span>
                <span v-if="record.status == 10">已终止</span>
              </template>

              <template v-if="tabsId == 2" slot="statusName" slot-scope="text ,record">
                  <span >{{record.statusName}}</span>
              </template>

              <template  slot="questionNo" slot-scope="text, record">
                <a type="link" @click="handleAction(1, record)">{{ text }}</a>
              </template>
              <template  v-if="tabsId == 2" slot="businessNo" slot-scope="text, record">
                <a type="link" @click="handleAction(2, record)">{{ text }}</a>
              </template>
            </a-table>
          </section>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import indexHeader from '@/views/components/indexHeader';
import { getRiskAction, postRiskAction } from '@/api/manage';
import { CommonMixis } from '@/mixins/CommonMixis';
export default {
  name: 'MatrixLssueInfo',
  mixins: [CommonMixis],
  components: {
    indexHeader
  },
  provide(){
    return {parentThis :  this}
  },
  data() {
    return {
      form:{},
      id: this.$route.query.id,
      tabsList: [
        { name: '问题单列表', key: 1 },
        { name: '优化单列表', key: 2 },
      ],
      tabsId: 1,
      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '30', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条';
        },
        total: 0,
        loading: false,
      },
      dataColumns: [
        { title: '问题单号', width: 120, dataIndex: 'questionNo', scopedSlots: { customRender: 'questionNo' } },
        { title: '发起部门', dataIndex: 'deptName', align: 'center', width: 120 },
        { title: '发起人',width: 120,dataIndex: 'submitUser',},
        { title: '发起时间',width: 100,dataIndex: 'createTime',},
        { title: '具体问题描述',
          width: 120,
          dataIndex: 'questionDesc',
          scopedSlots: { customRender: 'questionDesc' } },
        { title: '三年内是否首次发现问题',width: 100,dataIndex: 'threeFirstTime',align: 'center',
          customRender:(text,record) => {
            if(record.questionNo){
              if (text ) {
                return '是';
              } else {
                return '否';
              }
            }else{
              return '';
            }
          }
        },
        { title: '问题分类',width: 100,dataIndex: 'questionClassName',align: 'center',},
        { title: '问题评级',width: 100,dataIndex: 'questionGradeName',align: 'center',},
        { title: '计划完成时间', width: 120, dataIndex: 'planTime' },
        { title: '实际完成时间', width: 120, dataIndex: 'closeTime' },
        { title: '是否逾期', width: 110, dataIndex: 'isOvertime', scopedSlots: { customRender: 'isFlag' } },
        {
          title: '状态',
          width: 80,
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' }
        },
      ],
      dataColumns2: [
        {
          title: '优化单号',
          dataIndex: 'optNo',
          align: 'center',
          width: 100,
          scopedSlots: { customRender: 'businessNo' }
        },
        { title: '发起部门', dataIndex: 'deptName', align: 'center', width: 120 },
        { title: '发起人',width: 120,dataIndex: 'submitUser',},
        { title: '发起时间',width: 100,dataIndex: 'createTime',},
        { title: '计划完成时间', width: 120, dataIndex: 'planTime' },
        { title: '实际完成时间', width: 120, dataIndex: 'finishTime' },
        { title: '是否逾期', width: 110, dataIndex: 'isOvertime', scopedSlots: { customRender: 'isFlag' } },
        {
          title: '状态',
          width: 80,
          dataIndex: 'statusName',
          scopedSlots: { customRender: 'statusName' }
        },
      ],
      dataList: [],
      url: {
        list: '/incQuestion/riskPage',
        optList: '/incOpt/page',
        riskList:'/incRiskSpread/page',
      },
    };
  },
  mounted() {
    let riskId  = this.$route.query.id
    let companyCode = this.$route.query.companyCode;
    let manageCode = this.$route.query.manageCode;
    let businessModelId = this.$route.query.businessModelId;
    this.$set(this.pagination , 'riskId' , riskId)
    this.$set(this.pagination , 'companyCode' ,companyCode)
    this.$set(this.pagination , 'manageCode' ,manageCode)
    this.$set(this.pagination , 'businessModelId' ,businessModelId)
    this.initData();
    this.getInitData(this.url.list);

  },
  methods: {
    handChange(item) {
      this.tabsId = item.key;
      this.pagination.current = 1;
      if (item.key == 2){
        this.getInitData(this.url.optList)
      }
      else {
        this.getInitData(this.url.list);
      }
    },
    /**
     * 查询列表
     */
    pageChange(page) {
      this.pagination.current = page.current;
      this.pagination.pageSize = page.pageSize;

      if (this.tabsId ==1){
        this.getInitData(this.url.list);
      }
      if (this.tabsId == 2){
        this.getInitData(this.url.optList);
      }
    },
    handleCreate(value , item){
      var path
      var routeUrl
      if (value == 1){
         path =  `/internal/pro/addlssue`
         routeUrl = this.$router.resolve({
          path: path,
          query:{
            riskId:this.pagination.riskId ,
            companyCode:this.pagination.companyCode ,
            manageCode:this.pagination.manageCode

          }
        });
        window.open(routeUrl.href, '_blank');
      }
      if (value == 2){
        // this.$refs.createQuestion.handleEdit();
         path =  `/internal/opt/addlssue`
         routeUrl = this.$router.resolve({
          path: path,
          query:{
            riskId :this.pagination.riskId ,
            companyCode:this.pagination.companyCode ,
            manageCode:this.pagination.manageCode
          }
        });
        window.open(routeUrl.href, '_blank');
      }
    },
    initDetail(){

    },
    initData(){
      getRiskAction(this.url.riskList,{
        pageNo: 1,
        pageSize: 2,
        keyword: this.pagination.keyword,
        riskId:this.pagination.riskId,
        companyCode: this.pagination.companyCode,
        businessModelId: this.pagination.businessModelId,
        manageCode: this.pagination.manageCode,
      })
        .then(res => {
          const result = res.data;
          if (res.code === 0) {
            this.form = result.records[0];
            console.log('详情数据' , this.form)
          } else {
            this.$message.error('查询列表失败');
          }
          this.pagination.loading = false;
        });
    } ,
    handleAction(type,item){
      debugger
      var path;
      var routeUrl
      if (type == 1){
         path = item.status>1? `/internal/pro/detlssue`: `/internal/pro/addlssue`
         routeUrl = this.$router.resolve({
          path: path,
          query:{id:item.questionId}
        });
        window.open(routeUrl.href, '_blank');
      }

      if (type == 2){
         path = item.status>2? `/internal/opt/detlssue`: `/internal/opt/addlssue`
         routeUrl = this.$router.resolve({
          path: path,
          query:{id:item.id}
        });

        window.open(routeUrl.href, '_blank');
      }

    },
    getInitData(value) {
      this.pagination.loading = true;
      getRiskAction(value, {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        keyword: this.pagination.keyword,
        companyCode: this.pagination.companyCode,
        businessModelId: this.pagination.businessModelId,
        manageCode: this.pagination.manageCode,
        status: this.pagination.status,
        dataType: this.pagination.dataType,
        isOvertime:this.pagination.isOvertime,
        deptId:this.pagination.deptId,
        riskId:this.pagination.riskId
      }).then(res => {
        const result = res.data;
        if (res.code === 0) {
          this.dataList = result.records;
          this.pagination.total = result.total;
        } else {
          this.$message.error('查询列表失败');
        }

      });
      this.pagination.loading = false;
    },
  }
};
</script>
<style lang="scss" scoped>
@import '@/styles/riskForm.scss';
@import '@/styles/riskDetInfo.scss';
.mt20{
  margin-top: 20px;
}
.info-2 ::v-deep .ant-descriptions-item{display: flex !important;}
.info-main .info-2.ant-descriptions{margin: -20px 20px 20px;}
.section-bg{
  background-color: #F4F5F9;
  padding: 20px;
  /deep/ .ant-table{background-color: #fff;}
}
.tabs {
    display: flex;
    > div {
      height: 40px;
      color: #666;
      padding: 0 30px;
      line-height: 38px;
      cursor: pointer;
      font-size: 15px;
      &.active {
        background: #fff;
        position: relative;
        color: #1890ff;
        border-bottom: none;
        &:after {
          content: '';
          position: absolute;
          z-index: 1;
          width: 100%;
          height: 4px;
          background: #1890ff;
          left: 0;
          bottom: -2px;
        }
      }
      &:hover {
        color: #197ddb;
      }
    }
    + section {
      margin-top: 0;
    }
  }
</style>
